package com.cmes.core;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * 带统计数据的分页类
 *
 * @author Bruce.Gong
 * @since 1.0.1-SNAPSHOT
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
@NoArgsConstructor
public class PaginationSummary<T, E> extends Pagination<T> {

    private E summary;

    public PaginationSummary(int page, int pageSize) {
        super(page, pageSize);
    }

    public PaginationSummary(int page, int pageSize, boolean searchCount) {
        super(page, pageSize, searchCount);
    }

    public PaginationSummary(List<T> rows, long totalRow, int page, int pageSize) {
        super(page, pageSize);
        of(rows, totalRow);
    }

    public static <T, E> PaginationSummary<T, E> of(Pagination<T> pagination, E summary) {
        PaginationSummary<T, E> page = new PaginationSummary<>(pagination.getPageNum(), pagination.getPageSize());
        page.of(pagination.getRows(), pagination.getTotalRow());
        page.setSummary(summary);
        return page;
    }

}
